<?php

class SiteConfigForm extends CFormModel
{
	public $id_config;
	public $general_ssl;
	public $general_language;
	public $general_autorefreshcpdata;
	public $log_login;
	public $log_action;
	public $log_purgetime;
	public $security_max_failed_login;
	public $security_captcha;
	public $security_pwd_rotation;
	public $email_type;
	public $email_from_address;
	public $email_from_name;
	public $smtp_host;
	public $smtp_port;
	public $smtp_username;
	public $smtp_password;
	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return SiteConfig::model()->rules();
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_config' => t('info', 'Id Config'),
			'general_ssl' => t('info', 'SSL Options'),
			'general_language' => t('info', 'Language'),
			'general_autorefreshcpdata' => t('info', 'Auto-Pull Fresh cPanel Data'),
			'log_login' => t('info', 'Login Activity'),
			'log_action' => t('info', 'Action Log'),
			'log_purgetime' => t('info', 'Purge Logs'),
			'security_max_failed_login' => t('info', 'Max Failed Login Attempts'),
			'security_captcha' => t('info', 'Login Captcha'),
			'security_pwd_rotation' => t('info', 'Password Rotation'),
			'email_type' => t('info', 'Mail Type'),
			'email_from_address' => t('info', 'System Email From Address'),
			'email_from_name' => t('info', 'System Email From Name'),
			'smtp_host' => t('info', 'SMTP Host'),
			'smtp_port' => t('info', 'SMTP Port'),
			'smtp_username' => t('info', 'SMTP Username'),
			'smtp_password' => t('info', 'SMTP Password')
		);
	}

	public function getFieldLabel($field)
	{
		$labels = $this->attributeLabels();
		
		return empty($labels[$field])? '' : $labels[$field];
	}

	public function listSsl()
	{
		return array(
			SiteConfig::SSL_HTTP => t('info', 'Use HTTP'),
			SiteConfig::SSL_HTTPS => t('info', 'Use HTTPS')
		);
	}
	
	public function listLanguage()
	{
		return array(
			SiteConfig::LANGUAGE_EN => 'English',
			SiteConfig::LANGUAGE_ESP => 'Español',
			SiteConfig::LANGUAGE_LE => 'Le Français',
			SiteConfig::LANGUAGE_DEU => 'Deutsch'
		);
	}
	
	public function listAutoPullCpData()
	{
		return array(
			SiteConfig::AUTOREFRESHCPDATA_DISABLED => t('info', 'Disabled'),
			SiteConfig::AUTOREFRESHCPDATA_HOURLY => t('info', 'Hourly'),
			SiteConfig::AUTOREFRESHCPDATA_DAILY => t('info', 'Daily'),
			SiteConfig::AUTOREFRESHCPDATA_WEEKLY => t('info', 'Weekly')
		);
	}

	
	public function listPurgeTime()
	{
		return array(
			SiteConfig::PURGE_LOG_1DAY => t('info', 'Older than 1 day.'),
			SiteConfig::PURGE_LOG_7DAY => t('info', 'Older than 7 days.'),
			SiteConfig::PURGE_LOG_14DAY => t('info', 'Older than 14 days.'),
			SiteConfig::PURGE_LOG_30DAY => t('info', 'Older than 30 days.'),
			SiteConfig::PURGE_LOG_60DAY => t('info', 'Older than 60 days.'),
		);
	}
	
	public function listEnDis()
	{
		return array(
			SiteConfig::ENABLE => t('info', 'Enabled'),
			SiteConfig::DISABLE => t('info', 'Disabled'),
		);
	}
	
	public function listMailType()
	{
		return array(
			SiteConfig::MAIL_ORI => 'PHP Mail()',
			SiteConfig::MAIL_SMTP => 'SMTP',
		);
	}
	
	public function setValue($siteConfig)
	{
		$this->id_config = $siteConfig->id_config_value;
		$this->general_ssl = $siteConfig->general_ssl_value;
		$this->general_language = $siteConfig->general_language_value;
		$this->general_autorefreshcpdata = $siteConfig->general_autorefreshcpdata_value;
		$this->log_login = $siteConfig->log_login_value;
		$this->log_action = $siteConfig->log_action_value;
		$this->log_purgetime = $siteConfig->log_purgetime_value;
		$this->security_max_failed_login = $siteConfig->security_max_failed_login_value;
		$this->security_captcha = $siteConfig->security_captcha_value;
		$this->security_pwd_rotation = $siteConfig->security_pwd_rotation_value;
		$this->email_type = $siteConfig->email_type_value;
		$this->email_from_address = $siteConfig->email_from_address_value;
		$this->email_from_name = $siteConfig->email_from_name_value;
		$this->smtp_host = $siteConfig->smtp_host_value;
		$this->smtp_port = $siteConfig->smtp_port_value;
		$this->smtp_username = $siteConfig->smtp_username_value;
		$this->smtp_password = $siteConfig->smtp_password_value;		
	}
}